/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SocioEntryForm.java
 *
 * Created on Apr 10, 2011, 4:04:35 PM
 */

package mutual;

import java.awt.Dialog;
import javax.persistence.EntityManager;
import javax.persistence.RollbackException;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import mutual.entidades.Socios;
import mutual.entidades.SociosPK;


public class SocioEntryForm extends JPanel {
    
    EntityManager entityManager;
    Socios s;

    public SocioEntryForm(EntityManager em){
        entityManager = em;
        initComponents();
    }

    public SocioEntryForm(EntityManager em, Socios s){
        entityManager = em;
        this.s = s;
        initComponents();
        setSocio(s);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(mutual.MutualApp.class).getContext().getResourceMap(SocioEntryForm.class);
        ciudadesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("ciudadesQuery.query")); // NOI18N
        ciudadesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ciudadesQuery.getResultList();
        nacionalidadesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("nacionalidadesQuery.query")); // NOI18N
        estadoCivilQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("estadoCivilQuery.query")); // NOI18N
        tipoDocumentoQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("tipoDocumentoQuery.query")); // NOI18N
        tipoDocumentoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : tipoDocumentoQuery.getResultList();
        nacionalidadesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : nacionalidadesQuery.getResultList();
        estadoCivilList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : estadoCivilQuery.getResultList();
        dependenciaUniversitariaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("dependenciaUniversitariaQuery.query")); // NOI18N
        dependenciaUniversitariaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : dependenciaUniversitariaQuery.getResultList();
        actividadesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("actividadesQuery.query")); // NOI18N
        actividadesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : actividadesQuery.getResultList();
        categoriaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("categoriaQuery.query")); // NOI18N
        categoriaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : categoriaQuery.getResultList();
        apellidoLabel = new javax.swing.JLabel();
        nombreLabel = new javax.swing.JLabel();
        fechaNacimientoLabel = new javax.swing.JLabel();
        nacionalidadLabel = new javax.swing.JLabel();
        estadoCivilLabel = new javax.swing.JLabel();
        actividadLabel = new javax.swing.JLabel();
        dependenciaUniversitariaLabel = new javax.swing.JLabel();
        calleDomicilioLabel = new javax.swing.JLabel();
        numeroDomicilioLabel = new javax.swing.JLabel();
        departamentoLabel = new javax.swing.JLabel();
        pisoLabel = new javax.swing.JLabel();
        ciudadLabel = new javax.swing.JLabel();
        categoriaLabel = new javax.swing.JLabel();
        legajoLabel = new javax.swing.JLabel();
        telefonoParticularLabel = new javax.swing.JLabel();
        emailLabel = new javax.swing.JLabel();
        bloqueadoLabel = new javax.swing.JLabel();
        apellidoField = new javax.swing.JTextField();
        nombreField = new javax.swing.JTextField();
        calleDomicilioField = new javax.swing.JTextField();
        numeroDomicilioField = new javax.swing.JTextField();
        departamentoField = new javax.swing.JTextField();
        pisoField = new javax.swing.JTextField();
        legajoField = new javax.swing.JTextField();
        telefonoParticularField = new javax.swing.JTextField();
        emailField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        fechaNacimientoField = new org.jdesktop.swingx.JXDatePicker();
        ciudadField = new javax.swing.JComboBox();
        bloqueadoField = new javax.swing.JCheckBox();
        addEstadoCivilButton = new javax.swing.JButton();
        addCiudadesButton = new javax.swing.JButton();
        tipoDocumentoLabel = new javax.swing.JLabel();
        tipoDocumentoField = new javax.swing.JComboBox();
        addTipoDocumentoButton = new javax.swing.JButton();
        numeroDocumentoLabel = new javax.swing.JLabel();
        numeroDocumentoField = new javax.swing.JTextField();
        estadoCivilField = new javax.swing.JComboBox();
        nacionalidadField = new javax.swing.JComboBox();
        addNacionalidadButton = new javax.swing.JButton();
        addDependenciaUniversitariaButton = new javax.swing.JButton();
        dependenciaUniversitariaField = new javax.swing.JComboBox();
        statusLabel = new javax.swing.JLabel();
        addActividadButton = new javax.swing.JButton();
        actividadField = new javax.swing.JComboBox();
        addCategoriaButton = new javax.swing.JButton();
        categoriaField = new javax.swing.JComboBox();
        telefonoCelularLabel = new javax.swing.JLabel();
        telefonoLaboralLabel = new javax.swing.JLabel();
        telefonoCelularField = new javax.swing.JTextField();
        telefonoLaboralField = new javax.swing.JTextField();

        FormListener formListener = new FormListener();

        setName("Form"); // NOI18N
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        apellidoLabel.setText(resourceMap.getString("apellidoLabel.text")); // NOI18N
        apellidoLabel.setName("apellidoLabel"); // NOI18N
        add(apellidoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 52, 129, -1));

        nombreLabel.setText(resourceMap.getString("nombreLabel.text")); // NOI18N
        nombreLabel.setName("nombreLabel"); // NOI18N
        add(nombreLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 85, 129, -1));

        fechaNacimientoLabel.setText(resourceMap.getString("fechaNacimientoLabel.text")); // NOI18N
        fechaNacimientoLabel.setName("fechaNacimientoLabel"); // NOI18N
        add(fechaNacimientoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 127, 129, -1));

        nacionalidadLabel.setText(resourceMap.getString("nacionalidadLabel.text")); // NOI18N
        nacionalidadLabel.setName("nacionalidadLabel"); // NOI18N
        add(nacionalidadLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(304, 127, -1, -1));

        estadoCivilLabel.setText(resourceMap.getString("estadoCivilLabel.text")); // NOI18N
        estadoCivilLabel.setName("estadoCivilLabel"); // NOI18N
        add(estadoCivilLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(645, 127, 79, -1));

        actividadLabel.setText(resourceMap.getString("actividadLabel.text")); // NOI18N
        actividadLabel.setName("actividadLabel"); // NOI18N
        add(actividadLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 240, 129, -1));

        dependenciaUniversitariaLabel.setText(resourceMap.getString("dependenciaUniversitariaLabel.text")); // NOI18N
        dependenciaUniversitariaLabel.setName("dependenciaUniversitariaLabel"); // NOI18N
        add(dependenciaUniversitariaLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 245, 179, -1));

        calleDomicilioLabel.setText(resourceMap.getString("calleDomicilioLabel.text")); // NOI18N
        calleDomicilioLabel.setName("calleDomicilioLabel"); // NOI18N
        add(calleDomicilioLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 165, 129, -1));

        numeroDomicilioLabel.setText(resourceMap.getString("numeroDomicilioLabel.text")); // NOI18N
        numeroDomicilioLabel.setName("numeroDomicilioLabel"); // NOI18N
        add(numeroDomicilioLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 165, -1, -1));

        departamentoLabel.setText(resourceMap.getString("departamentoLabel.text")); // NOI18N
        departamentoLabel.setName("departamentoLabel"); // NOI18N
        add(departamentoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(625, 165, 101, -1));

        pisoLabel.setText(resourceMap.getString("pisoLabel.text")); // NOI18N
        pisoLabel.setName("pisoLabel"); // NOI18N
        add(pisoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(825, 165, 42, -1));

        ciudadLabel.setText(resourceMap.getString("ciudadLabel.text")); // NOI18N
        ciudadLabel.setName("ciudadLabel"); // NOI18N
        add(ciudadLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 200, 129, -1));

        categoriaLabel.setText(resourceMap.getString("categoriaLabel.text")); // NOI18N
        categoriaLabel.setName("categoriaLabel"); // NOI18N
        add(categoriaLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 285, 129, -1));

        legajoLabel.setText(resourceMap.getString("legajoLabel.text")); // NOI18N
        legajoLabel.setName("legajoLabel"); // NOI18N
        add(legajoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 285, 56, -1));

        telefonoParticularLabel.setText(resourceMap.getString("telefonoParticularLabel.text")); // NOI18N
        telefonoParticularLabel.setName("telefonoParticularLabel"); // NOI18N
        add(telefonoParticularLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 330, 129, -1));

        emailLabel.setText(resourceMap.getString("emailLabel.text")); // NOI18N
        emailLabel.setName("emailLabel"); // NOI18N
        add(emailLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 440, 129, -1));

        bloqueadoLabel.setText(resourceMap.getString("bloqueadoLabel.text")); // NOI18N
        bloqueadoLabel.setName("bloqueadoLabel"); // NOI18N
        add(bloqueadoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 480, 129, -1));

        apellidoField.setName("apellidoField"); // NOI18N
        add(apellidoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 47, 780, -1));

        nombreField.setName("nombreField"); // NOI18N
        add(nombreField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 80, 780, -1));

        calleDomicilioField.setName("calleDomicilioField"); // NOI18N
        add(calleDomicilioField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 160, 250, -1));

        numeroDomicilioField.setName("numeroDomicilioField"); // NOI18N
        add(numeroDomicilioField, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 160, 120, -1));

        departamentoField.setName("departamentoField"); // NOI18N
        add(departamentoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(735, 160, 64, -1));

        pisoField.setName("pisoField"); // NOI18N
        add(pisoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(875, 160, 55, -1));

        legajoField.setName("legajoField"); // NOI18N
        add(legajoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 280, 390, -1));

        telefonoParticularField.setName("telefonoParticularField"); // NOI18N
        add(telefonoParticularField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 320, 780, -1));

        emailField.setName("emailField"); // NOI18N
        add(emailField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 440, 780, -1));

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N
        saveButton.addActionListener(formListener);
        add(saveButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(850, 510, -1, -1));

        fechaNacimientoField.setFormats("dd/MM/yyyy");
        fechaNacimientoField.setName("fechaNacimientoField"); // NOI18N
        add(fechaNacimientoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 122, -1, -1));

        ciudadField.setName("ciudadField"); // NOI18N

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ciudadesList, ciudadField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(ciudadField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 200, 740, -1));

        bloqueadoField.setText(resourceMap.getString("bloqueadoField.text")); // NOI18N
        bloqueadoField.setName("bloqueadoField"); // NOI18N
        add(bloqueadoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 480, -1, -1));

        addEstadoCivilButton.setText(resourceMap.getString("addEstadoCivilButton.text")); // NOI18N
        addEstadoCivilButton.setName("addEstadoCivilButton"); // NOI18N
        addEstadoCivilButton.addActionListener(formListener);
        add(addEstadoCivilButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(895, 120, 38, 25));

        addCiudadesButton.setText(resourceMap.getString("addCiudadesButton.text")); // NOI18N
        addCiudadesButton.setName("addCiudadesButton"); // NOI18N
        addCiudadesButton.addActionListener(formListener);
        add(addCiudadesButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(895, 200, 38, 25));

        tipoDocumentoLabel.setText(resourceMap.getString("tipoDocumentoLabel.text")); // NOI18N
        tipoDocumentoLabel.setName("tipoDocumentoLabel"); // NOI18N
        add(tipoDocumentoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 18, -1, -1));

        tipoDocumentoField.setName("tipoDocumentoField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipoDocumentoList, tipoDocumentoField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(tipoDocumentoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 13, 123, -1));

        addTipoDocumentoButton.setText(resourceMap.getString("addTipoDocumentoButton.text")); // NOI18N
        addTipoDocumentoButton.setName("addTipoDocumentoButton"); // NOI18N
        addTipoDocumentoButton.addActionListener(formListener);
        add(addTipoDocumentoButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 12, 38, 25));

        numeroDocumentoLabel.setText(resourceMap.getString("numeroDocumentoLabel.text")); // NOI18N
        numeroDocumentoLabel.setName("numeroDocumentoLabel"); // NOI18N
        add(numeroDocumentoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(325, 18, -1, -1));

        numeroDocumentoField.setText(resourceMap.getString("numeroDocumentoField.text")); // NOI18N
        numeroDocumentoField.setName("numeroDocumentoField"); // NOI18N
        add(numeroDocumentoField, new org.netbeans.lib.awtextra.AbsoluteConstraints(485, 10, 450, -1));

        estadoCivilField.setName("estadoCivilField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, estadoCivilList, estadoCivilField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(estadoCivilField, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 120, 160, -1));

        nacionalidadField.setName("nacionalidadField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, nacionalidadesList, nacionalidadField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(nacionalidadField, new org.netbeans.lib.awtextra.AbsoluteConstraints(402, 122, 190, -1));

        addNacionalidadButton.setText(resourceMap.getString("addNacionalidadButton.text")); // NOI18N
        addNacionalidadButton.setName("addNacionalidadButton"); // NOI18N
        addNacionalidadButton.addActionListener(formListener);
        add(addNacionalidadButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 120, 38, 25));

        addDependenciaUniversitariaButton.setText(resourceMap.getString("addDependenciaUniversitariaButton.text")); // NOI18N
        addDependenciaUniversitariaButton.setName("addDependenciaUniversitariaButton"); // NOI18N
        addDependenciaUniversitariaButton.addActionListener(formListener);
        add(addDependenciaUniversitariaButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(895, 240, 38, 25));

        dependenciaUniversitariaField.setName("dependenciaUniversitariaField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, dependenciaUniversitariaList, dependenciaUniversitariaField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(dependenciaUniversitariaField, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 240, 280, -1));

        statusLabel.setFont(resourceMap.getFont("statusLabel.font")); // NOI18N
        statusLabel.setForeground(resourceMap.getColor("statusLabel.foreground")); // NOI18N
        statusLabel.setText(resourceMap.getString("statusLabel.text")); // NOI18N
        statusLabel.setName("statusLabel"); // NOI18N
        add(statusLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 520, -1, 21));

        addActividadButton.setText(resourceMap.getString("addActividadButton.text")); // NOI18N
        addActividadButton.setName("addActividadButton"); // NOI18N
        addActividadButton.addActionListener(formListener);
        add(addActividadButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 240, 38, 25));

        actividadField.setName("actividadField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, actividadesList, actividadField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(actividadField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 240, 220, -1));

        addCategoriaButton.setText(resourceMap.getString("addCategoriaButton.text")); // NOI18N
        addCategoriaButton.setName("addCategoriaButton"); // NOI18N
        addCategoriaButton.addActionListener(formListener);
        add(addCategoriaButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 280, 38, 25));

        categoriaField.setName("categoriaField"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, categoriaList, categoriaField);
        bindingGroup.addBinding(jComboBoxBinding);

        add(categoriaField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 280, 287, -1));

        telefonoCelularLabel.setText(resourceMap.getString("telefonoCelularLabel.text")); // NOI18N
        telefonoCelularLabel.setName("telefonoCelularLabel"); // NOI18N
        add(telefonoCelularLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 365, -1, -1));

        telefonoLaboralLabel.setText(resourceMap.getString("telefonoLaboralLabel.text")); // NOI18N
        telefonoLaboralLabel.setName("telefonoLaboralLabel"); // NOI18N
        add(telefonoLaboralLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 400, -1, -1));

        telefonoCelularField.setText(resourceMap.getString("telefonoCelularField.text")); // NOI18N
        telefonoCelularField.setName("telefonoCelularField"); // NOI18N
        add(telefonoCelularField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 360, 780, -1));

        telefonoLaboralField.setText(resourceMap.getString("telefonoLaboralField.text")); // NOI18N
        telefonoLaboralField.setName("telefonoLaboralField"); // NOI18N
        add(telefonoLaboralField, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 400, 780, -1));

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == saveButton) {
                SocioEntryForm.this.saveButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addEstadoCivilButton) {
                SocioEntryForm.this.addEstadoCivilButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addCiudadesButton) {
                SocioEntryForm.this.addCiudadesButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addTipoDocumentoButton) {
                SocioEntryForm.this.addTipoDocumentoButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addNacionalidadButton) {
                SocioEntryForm.this.addNacionalidadButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addDependenciaUniversitariaButton) {
                SocioEntryForm.this.addDependenciaUniversitariaButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addActividadButton) {
                SocioEntryForm.this.addActividadButtonActionPerformed(evt);
            }
            else if (evt.getSource() == addCategoriaButton) {
                SocioEntryForm.this.addCategoriaButtonActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    private void setSocio(Socios s){

        tipoDocumentoField.setSelectedItem(s.getTipoDocumento1());
        numeroDocumentoField.setText(s.getSociosPK().getNumeroDocumento()+"");
        apellidoField.setText(s.getApellido());
        nombreField.setText(s.getNombre());
        fechaNacimientoField.setDate(s.getFechaNacimiento());
        nacionalidadField.setSelectedItem(s.getNacionalidades());
        estadoCivilField.setSelectedItem(s.getEstadoCivil());
        calleDomicilioField.setText(s.getCalleDomicilio());
        numeroDomicilioField.setText(s.getNumeroDomicilio()+"");
        departamentoField.setText(s.getDepartamento());
        pisoField.setText(s.getPiso());
        ciudadField.setSelectedItem(s.getCiudades());
        actividadField.setSelectedItem(s.getActividades());
        dependenciaUniversitariaField.setSelectedItem(s.getDependenciaUniversitaria());
        categoriaField.setSelectedItem(s.getCategoriasSocio());
        legajoField.setText(s.getLegajo()+"");
        telefonoParticularField.setText(s.getTelefonoParticular());
        telefonoLaboralField.setText(s.getTelefonoLaboral());
        telefonoCelularField.setText(s.getTelefonoCelular());
        bloqueadoField.setSelected(s.getBloqueado());
        emailField.setText(s.getEmail());
    }

    private Socios getSocio(){

        Socios s = new mutual.entidades.Socios();

        mutual.entidades.TipoDocumento td = (mutual.entidades.TipoDocumento)tipoDocumentoField.getSelectedItem();
        SociosPK spk = new SociosPK(td.getId(), Integer.parseInt(numeroDocumentoField.getText()));
        s.setTipoDocumento1(td);
        s.setSociosPK(spk);
        s.setApellido(apellidoField.getText());
        s.setNombre(nombreField.getText());
        s.setFechaNacimiento(fechaNacimientoField.getDate());
        s.setNacionalidades((mutual.entidades.Nacionalidades)nacionalidadField.getSelectedItem());
        s.setEstadoCivil((mutual.entidades.EstadoCivil)estadoCivilField.getSelectedItem());
        s.setCalleDomicilio(calleDomicilioField.getText());
        s.setNumeroDomicilio(Integer.parseInt(numeroDomicilioField.getText()));
        s.setDepartamento(departamentoField.getText());
        s.setPiso(pisoField.getText());
        s.setCiudades((mutual.entidades.Ciudades)ciudadField.getSelectedItem());
        s.setActividades((mutual.entidades.Actividades)actividadField.getSelectedItem());
        s.setDependenciaUniversitaria((mutual.entidades.DependenciaUniversitaria)dependenciaUniversitariaField.getSelectedItem());
        s.setCategoriasSocio((mutual.entidades.CategoriasSocio)categoriaField.getSelectedItem());
        s.setLegajo(Integer.parseInt(legajoField.getText()));
        s.setTelefonoParticular(telefonoParticularField.getText());
        s.setTelefonoLaboral(telefonoLaboralField.getText());
        s.setTelefonoCelular(telefonoCelularField.getText());
        s.setBloqueado(bloqueadoField.isSelected());
        s.setEmail(emailField.getText());
        /*int numeroDomicilio;
        try{
            numeroDomicilio = Integer.parseInt(numeroDomicilioField.getText());
        }
        catch (Exception e){
            numeroDomicilio = 0;
        }*/
        return s;
    }
        
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        //borro anterior
        entityManager.remove(s);
        entityManager.getTransaction().commit();
        entityManager.getTransaction().begin();

        //agrego nueva
        Socios s = getSocio();
        entityManager.persist(s);
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
            dialog.dispose();
        } catch (RollbackException rex) {
            rex.printStackTrace();
            statusLabel.setText(rex.getLocalizedMessage());
            entityManager.getTransaction().begin();
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void addCiudadesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCiudadesButtonActionPerformed
        new CiudadesForm(entityManager).showDialog(frame);
        refreshQuery(ciudadesQuery, ciudadesList, ciudadField);
    }//GEN-LAST:event_addCiudadesButtonActionPerformed

    private void addEstadoCivilButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEstadoCivilButtonActionPerformed
        new EstadoCivilForm(entityManager).showDialog(frame);
        refreshQuery(estadoCivilQuery, estadoCivilList, estadoCivilField);
    }//GEN-LAST:event_addEstadoCivilButtonActionPerformed

    private void addNacionalidadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNacionalidadButtonActionPerformed
        new NacionalidadesForm(entityManager).showDialog(frame);
        refreshQuery(nacionalidadesQuery, nacionalidadesList, nacionalidadField);
    }//GEN-LAST:event_addNacionalidadButtonActionPerformed

    private void addTipoDocumentoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTipoDocumentoButtonActionPerformed
        new TipoDocumentoForm(entityManager).showDialog(frame);
        refreshQuery(tipoDocumentoQuery, tipoDocumentoList, tipoDocumentoField);
    }//GEN-LAST:event_addTipoDocumentoButtonActionPerformed

    private void addDependenciaUniversitariaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDependenciaUniversitariaButtonActionPerformed
        new DependenciaUniversitariaForm(entityManager).showDialog(frame);
        refreshQuery(dependenciaUniversitariaQuery, dependenciaUniversitariaList, dependenciaUniversitariaField);
    }//GEN-LAST:event_addDependenciaUniversitariaButtonActionPerformed

    private void addActividadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActividadButtonActionPerformed
        new ActividadesForm(entityManager).showDialog(frame);
        refreshQuery(actividadesQuery, actividadesList, actividadField);
    }//GEN-LAST:event_addActividadButtonActionPerformed

    private void addCategoriaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCategoriaButtonActionPerformed
        new CategoriasSocioForm(entityManager).showDialog(frame);
        refreshQuery(categoriaQuery, categoriaList, categoriaField);
    }//GEN-LAST:event_addCategoriaButtonActionPerformed
    
    private void refreshQuery(javax.persistence.Query query, java.util.List list, JComboBox cb){
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
        cb.updateUI();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox actividadField;
    private javax.swing.JLabel actividadLabel;
    private java.util.List<mutual.entidades.Actividades> actividadesList;
    private javax.persistence.Query actividadesQuery;
    private javax.swing.JButton addActividadButton;
    private javax.swing.JButton addCategoriaButton;
    private javax.swing.JButton addCiudadesButton;
    private javax.swing.JButton addDependenciaUniversitariaButton;
    private javax.swing.JButton addEstadoCivilButton;
    private javax.swing.JButton addNacionalidadButton;
    private javax.swing.JButton addTipoDocumentoButton;
    private javax.swing.JTextField apellidoField;
    private javax.swing.JLabel apellidoLabel;
    private javax.swing.JCheckBox bloqueadoField;
    private javax.swing.JLabel bloqueadoLabel;
    private javax.swing.JTextField calleDomicilioField;
    private javax.swing.JLabel calleDomicilioLabel;
    private javax.swing.JComboBox categoriaField;
    private javax.swing.JLabel categoriaLabel;
    private java.util.List<mutual.entidades.CategoriasSocio> categoriaList;
    private javax.persistence.Query categoriaQuery;
    private javax.swing.JComboBox ciudadField;
    private javax.swing.JLabel ciudadLabel;
    private java.util.List<mutual.entidades.Ciudades> ciudadesList;
    private javax.persistence.Query ciudadesQuery;
    private javax.swing.JTextField departamentoField;
    private javax.swing.JLabel departamentoLabel;
    private javax.swing.JComboBox dependenciaUniversitariaField;
    private javax.swing.JLabel dependenciaUniversitariaLabel;
    private java.util.List<mutual.entidades.DependenciaUniversitaria> dependenciaUniversitariaList;
    private javax.persistence.Query dependenciaUniversitariaQuery;
    private javax.swing.JTextField emailField;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JComboBox estadoCivilField;
    private javax.swing.JLabel estadoCivilLabel;
    private java.util.List<mutual.entidades.EstadoCivil> estadoCivilList;
    private javax.persistence.Query estadoCivilQuery;
    private org.jdesktop.swingx.JXDatePicker fechaNacimientoField;
    private javax.swing.JLabel fechaNacimientoLabel;
    private javax.swing.JTextField legajoField;
    private javax.swing.JLabel legajoLabel;
    private javax.swing.JComboBox nacionalidadField;
    private javax.swing.JLabel nacionalidadLabel;
    private java.util.List<mutual.entidades.Nacionalidades> nacionalidadesList;
    private javax.persistence.Query nacionalidadesQuery;
    private javax.swing.JTextField nombreField;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JTextField numeroDocumentoField;
    private javax.swing.JLabel numeroDocumentoLabel;
    private javax.swing.JTextField numeroDomicilioField;
    private javax.swing.JLabel numeroDomicilioLabel;
    private javax.swing.JTextField pisoField;
    private javax.swing.JLabel pisoLabel;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JTextField telefonoCelularField;
    private javax.swing.JLabel telefonoCelularLabel;
    private javax.swing.JTextField telefonoLaboralField;
    private javax.swing.JLabel telefonoLaboralLabel;
    private javax.swing.JTextField telefonoParticularField;
    private javax.swing.JLabel telefonoParticularLabel;
    private javax.swing.JComboBox tipoDocumentoField;
    private javax.swing.JLabel tipoDocumentoLabel;
    private java.util.List<mutual.entidades.TipoDocumento> tipoDocumentoList;
    private javax.persistence.Query tipoDocumentoQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    
    static JFrame frame;
    private JDialog dialog;

    public void showDialog(JFrame parent){
        dialog = new JDialog(parent, "Agregar socios", Dialog.ModalityType.APPLICATION_MODAL);
        dialog.setContentPane(this);
        dialog.setSize(945,541);
        dialog.setVisible(true);
    }

}
